package com.zhupanlin.zhyl.hosp.controller.api;

import com.zhupanlin.zhyl.common.result.Result;
import com.zhupanlin.zhyl.common.util.HttpRequestHelper;
import com.zhupanlin.zhyl.hosp.service.DepartmentService;
import com.zhupanlin.zhyl.hosp.service.HospitalService;
import com.zhupanlin.zhyl.hosp.service.ScheduleService;
import com.zhupanlin.zhyl.model.hosp.Department;
import com.zhupanlin.zhyl.model.hosp.Hospital;
import com.zhupanlin.zhyl.model.hosp.Schedule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/11/23 17:53
 */
@RestController
@RequestMapping("/api/hosp")
public class ApiController {

    @Autowired
    private HospitalService hospitalService;

    @Autowired
    private DepartmentService departmentService;

    @Autowired
    private ScheduleService scheduleService;

    // 查询医院
    @PostMapping("hospital/show")
    public Result getHospital(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        // 调用 service 方法实现根据医院编号查询
        Hospital hospital = hospitalService.getHospitalByHoscoe(paramMap);
        return Result.ok(hospital);
    }


    // 上传医院接口
    @PostMapping("saveHospital")
    public Result saveHosp(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        // 调用 service 的方法
        hospitalService.save(paramMap);
        return Result.ok();
    }

    @PostMapping("saveDepartment")
    public Result saveDepartment(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        departmentService.save(paramMap);
        return Result.ok();
    }

    // 查询科室接口
    @PostMapping("department/list")
    public Result findDepartment(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        Page<Department> pageInfo = departmentService.findDepartmentList(paramMap);
        return Result.ok(pageInfo);
    }

    // 删除科室接口
    @PostMapping("department/remove")
    public Result removeDepartment(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        departmentService.removeDepartment(paramMap);

        return Result.ok();
    }

    // 上传排班接口

    @PostMapping("saveSchedule")
    public Result saveSchedule(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        scheduleService.save(paramMap);
        return Result.ok();


    }

    // 查询排班接口
    @PostMapping("schedule/list")
    public Result findSchedule(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        Page<Schedule> pageModel = scheduleService.findPageSchedule(paramMap);
        return Result.ok(pageModel);
    }

    // 删除排班接口
    @PostMapping("schedule/remove")
    public Result removeSchedule(HttpServletRequest request) {
        // 获取到传递过来的医院信息
        Map<String, Object> paramMap = HttpRequestHelper.switchMap(request.getParameterMap());

        scheduleService.removeSchedule(paramMap);
        return Result.ok();
    }
}
